/**
 * ライセンスを扱うモジュール
 * TODO: MSのライセンスだとかFSFだとかOSIだとか
 */

module nazo.license;
import std.metastrings, nazo.factory;

class License{
  abstract string name();
  abstract string descriptionHTML();
}

class NonDisplayLicense:License{
  override string name(){
    return "明示しない(非推奨)";
  }
  override string descriptionHTML(){
    return "";
  }
}

class EachOtherLicense:License{
  override string name(){
    return "著作権は書き込んだ者が保有";
  }
  override string descriptionHTML(){
    return "この文章の著作権は書き込んだ人それぞれが保有してます。";
  }
}

class AdminLicense:License{
  override string name(){
    return "著作権は管理人に帰属";
  }
  override string descriptionHTML(){
    return "この文章の著作権は管理人が全て保有してます。";
  }
}

class UndecidedLicense:License{
  override string name(){
    return "未定";
  }
  override string descriptionHTML(){
    return "この文章はライセンスが未定であり、今後管理人が第三者の書き込みを含め自由にライセンスを変更できるものとします。";
  }
}

class PublicDomainLicense:License{
  override string name(){
    return "パブリックドメイン";
  }
  override string descriptionHTML(){
    return "この文章の著作権は放棄します。";
  }
}

class SpecLicense:License{
  abstract string longname();
  abstract string uri();
  override string descriptionHTML(){
    return "この文章のライセンスは<a href=\""~uri()~"\">"~name()~"</a>です。";
  }
}

class GNULicense(int ver, bool weak, bool orlater):SpecLicense{
  override string name(){
    return (weak?"L":"")~"GPL "~ToString!(ver)~(orlater?" or later":"");
  }
  override string longname(){
    return "GNU "~(weak?"Lesser ":"")~"General Public License, version "~ToString!(ver)~(orlater?" or later":"");
  }
  override string uri(){
    static if(ver==2)
      return "http://www.gnu.org/licenses/old-licenses/"~(weak?"l":"")~"gpl-2."~(weak?"1":"0")~".html";
    else static if(ver==3)
      return "http://www.gnu.org/copyleft/"~(weak?"l":"")~"gpl.html";
    else
      static assert(0);
  }
}

enum Treatment{
  none,
  sa,
  nd,
}
class CreativeCommonsLicense(bool nc, Treatment treatment):SpecLicense{
  override string name(){
    return "CC 表示"~(nc?"-非営利":"")~(treatment==Treatment.sa?"-継承":(treatment==Treatment.nd?"-改変禁止":""))~" 3.0 Unported";
  }
  override string longname(){
    return "クリエイティブ・コモンズ 表示"~(nc?"-非営利":"")~(treatment==Treatment.sa?"-継承":(treatment==Treatment.nd?"-改変禁止":""))~" 3.0 Unported";
  }
  override string uri(){
    return "http://creativecommons.org/licenses/by"~(nc?"-nc":"")~(treatment==Treatment.sa?"-sa":(treatment==Treatment.nd?"-nd":""))~"/3.0/deed.ja";
  }
}

class FreeBSDDocumentationLicense:SpecLicense{
  override string name(){
    return "FreeBSD Documentation License";
  }
  override string longname(){
    return "The FreeBSD Documentation License";
  }
  override string uri(){
    return "http://www.freebsd.org/copyright/freebsd-doc-license.html";
  }
}

class GFDLLicense:SpecLicense{
  override string name(){
    return "GFDL";
  }
  override string longname(){
    return "GNU Free Documentation License";
  }
  override string uri(){
    return "http://www.gnu.org/licenses/fdl.txt";
  }
}

class NewBSDLicense:SpecLicense{
  override string name(){
    return "修正BSDライセンス";
  }
  override string longname(){
    return "修正BSDライセンス";
  }
  override string uri(){
    return "http://www.debian.org/misc/bsd.license";
  }
}

class ArtisticLicense:SpecLicense{
  override string name(){
    return "Artistic License";
  }
  override string longname(){
    return "The Artistic License";
  }
  override string uri(){
    return "http://www.perl.com/language/misc/Artistic.html";
  }
}

class ApacheLicense:SpecLicense{
  override string name(){
    return "Apache License v2";
  }
  override string longname(){
    return "Apache License, Version 2.0";
  }
  override string uri(){
    return "http://www.apache.org/licenses/LICENSE-2.0";
  }
}

class MitLicense:SpecLicense{
  override string name(){
    return "MIT License";
  }
  override string longname(){
    return "The MIT License";
  }
  override string uri(){
    return "http://www.opensource.org/licenses/mit-license.php";
  }
}

class NYSLLicense:SpecLicense{
  override string name(){
    return "NYSL";
  }
  override string longname(){
    return "NYSL Version 0.9982";
  }
  override string uri(){
    return "http://www.kmonos.net/nysl/";
  }
}

class KL01License:SpecLicense{
  override string name(){
    return "KL-01";
  }
  override string longname(){
    return "川合堂ライセンス01";
  }
  override string uri(){
    return "http://wiki.osdev.info/?%C0%EE%B9%E7%C6%B2%A5%E9%A5%A4%A5%BB%A5%F3%A5%B901";
  }
}

alias ListFactory!(NonDisplayLicense, EachOtherLicense, AdminLicense, UndecidedLicense, PublicDomainLicense,
                   GNULicense!(2,true,true), GNULicense!(2,true,false),
                   GNULicense!(2,false,true), GNULicense!(2,false,false),
                   GNULicense!(3,true,true), GNULicense!(3,true,false),
                   GNULicense!(3,false,true), GNULicense!(3,false,false),
                   CreativeCommonsLicense!(false, Treatment.none), CreativeCommonsLicense!(true, Treatment.none),
                   CreativeCommonsLicense!(false, Treatment.sa), CreativeCommonsLicense!(true, Treatment.sa),
                   CreativeCommonsLicense!(false, Treatment.nd), CreativeCommonsLicense!(true, Treatment.nd),
                   FreeBSDDocumentationLicense, GFDLLicense, NewBSDLicense, ArtisticLicense, ApacheLicense, MitLicense,
                   NYSLLicense, KL01License
                   ) LicenseFactory;
